/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
 * Description: hiudk sdk adapt
 * Author: ETH group
 * Create: 2021-07-30
 */

#ifndef HIUDK_SDK_HW_ADPT_H
#define HIUDK_SDK_HW_ADPT_H

#if defined(HIUDK_SDK_ADPT) && defined(HIUDK_SDK)
#include "hinic3_hw.h"
#include "hiudk_sdk_hw_comm_adpt.h"
static inline int sdk_msg_to_mgmt_sync(void *udkdev, u8 mod, u16 cmd, void *buf_in, u16 in_size,
				       void *buf_out, u16 *out_size, u32 timeout, u16 channel)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return -EINVAL;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_msg_to_mgmt_sync(sdk_hwdev, mod, cmd, buf_in, in_size, buf_out,
				       out_size, timeout, channel);
}

static inline int sdk_ppf_tmr_start(void *udkdev)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return -EINVAL;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_ppf_tmr_start(sdk_hwdev);
}

static inline int sdk_ppf_tmr_stop(void *udkdev)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return -EINVAL;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_ppf_tmr_stop(sdk_hwdev);
}

static inline int sdk_register_mgmt_msg_cb(void *udkdev, u8 mod, void *pri_handle,
					   hinic3_mgmt_msg_cb callback)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return -EINVAL;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_register_mgmt_msg_cb(sdk_hwdev, mod, pri_handle, callback);
}

static inline int sdk_register_pf_mbox_cb(void *udkdev, u8 mod, void *pri_handle,
					  hinic3_pf_mbox_cb callback)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return -EINVAL;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_register_pf_mbox_cb(sdk_hwdev, mod, pri_handle, callback);
}

static inline int sdk_register_ppf_mbox_cb(void *udkdev, u8 mod, void *pri_handle,
					   hinic3_ppf_mbox_cb callback)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return -EINVAL;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_register_ppf_mbox_cb(sdk_hwdev, mod, pri_handle, callback);
}

static inline int sdk_register_service_adapter(void *udkdev, void *service_adapter,
					       enum hinic3_service_type type)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return -EINVAL;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_register_service_adapter(sdk_hwdev, service_adapter, type);
}

static inline int sdk_register_vf_mbox_cb(void *udkdev, u8 mod, void *pri_handle,
					  hinic3_vf_mbox_cb callback)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return -EINVAL;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_register_vf_mbox_cb(sdk_hwdev, mod, pri_handle, callback);
}

static inline int sdk_set_root_ctxt(void *udkdev, u32 rq_depth, u32 sq_depth,
				    int rx_buf_sz, u16 channel)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return -EINVAL;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_set_root_ctxt(sdk_hwdev, rq_depth, sq_depth, rx_buf_sz, channel);
}

static inline int sdk_sm_ctr_rd64(void *udkdev, u8 node, u8 instance, u32 ctr_id, u64 *value)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return -EINVAL;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_sm_ctr_rd64(sdk_hwdev, node, instance, ctr_id, value);
}

static inline void sdk_unregister_mgmt_msg_cb(void *udkdev, u8 mod)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_unregister_mgmt_msg_cb(sdk_hwdev, mod);
}

static inline void sdk_unregister_pf_mbox_cb(void *udkdev, u8 mod)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_unregister_pf_mbox_cb(sdk_hwdev, mod);
}

static inline void sdk_unregister_ppf_mbox_cb(void *udkdev, u8 mod)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_unregister_ppf_mbox_cb(sdk_hwdev, mod);
}

static inline void sdk_unregister_service_adapter(void *udkdev, enum hinic3_service_type type)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_unregister_service_adapter(sdk_hwdev, type);
}

static inline void sdk_unregister_vf_mbox_cb(void *udkdev, u8 mod)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_unregister_vf_mbox_cb(sdk_hwdev, mod);
}

static inline int sdk_mbox_ppf_to_host(void *udkdev, u8 mod, u16 cmd, u8 host_id,
					 void *buf_in, u16 in_size, void *buf_out,
					 u16 *out_size, u32 timeout, u16 channel)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return -EINVAL;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_mbox_ppf_to_host(sdk_hwdev, mod, cmd, host_id,
				       buf_in, in_size, buf_out,
				       out_size, timeout, channel);
}
static inline int sdk_set_ceq_irq_disable(void *udkdev, u16 q_id)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return -EINVAL;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_set_ceq_irq_disable(sdk_hwdev, q_id);
}

static inline void sdk_force_complete_all(void *udkdev)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_force_complete_all(sdk_hwdev);
}

static inline int sdk_get_ceq_page_phy_addr(void *udkdev, u16 q_id,
				 u16 page_idx, u64 *page_phy_addr)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return -EINVAL;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_get_ceq_page_phy_addr(sdk_hwdev, q_id, page_idx, page_phy_addr);
}

static inline int sdk_get_ceq_info(void *udkdev, u16 q_id, struct hinic3_ceq_info *ceq_info)
{
	void *sdk_hwdev = NULL;

	if (!CHECK_UDK_DEV(udkdev)) {
		pr_err("udkdev is error! \n");
		return -EINVAL;
	}

	sdk_hwdev = GET_SDKHWDEV_FROM_HIUDKHWDEV(udkdev);
	return hinic3_get_ceq_info(sdk_hwdev, q_id, ceq_info);
}

#define hinic3_aeq_register_hw_cb    sdk_aeq_register_hw_cb
#define hinic3_aeq_register_swe_cb    sdk_aeq_register_swe_cb
#define hinic3_aeq_unregister_hw_cb    sdk_aeq_unregister_hw_cb
#define hinic3_aeq_unregister_swe_cb    sdk_aeq_unregister_swe_cb
#define hinic3_alloc_cmd_buf    sdk_alloc_cmd_buf
#define hinic3_alloc_db_addr    sdk_alloc_db_addr
#define hinic3_alloc_db_phy_addr    sdk_alloc_db_phy_addr
#define hinic3_api_csr_rd64    sdk_api_csr_rd64
#define hinic3_ceq_register_cb    sdk_ceq_register_cb
#define hinic3_ceq_unregister_cb    sdk_ceq_unregister_cb
#define hinic3_clean_root_ctxt    sdk_clean_root_ctxt
#define hinic3_cmdq_detail_resp    sdk_cmdq_detail_resp
#define hinic3_cmdq_direct_resp    sdk_cmdq_direct_resp
#define hinic3_cos_id_detail_resp    sdk_cos_id_detail_resp
#define hinic3_event_callback    sdk_event_callback
#define hinic3_free_cmd_buf    sdk_free_cmd_buf
#define hinic3_free_db_addr    sdk_free_db_addr
#define hinic3_free_db_phy_addr    sdk_free_db_phy_addr
#define hinic3_func_reset    sdk_func_reset
#define hinic3_get_board_info    sdk_get_board_info
#define hinic3_get_hw_pf_infos    sdk_get_hw_pf_infos
#define hinic3_get_service_adapter    sdk_get_service_adapter
#define hinic3_link_event_stats    sdk_link_event_stats
#define hinic3_mbox_to_pf    sdk_mbox_to_pf
#define hinic3_mbox_to_vf    sdk_mbox_to_vf
#define hinic3_mbox_to_vf_no_ack    sdk_mbox_to_vf_no_ack
#define hinic3_msg_to_mgmt_api_chain_async    sdk_msg_to_mgmt_api_chain_async
#define hinic3_msg_to_mgmt_async    sdk_msg_to_mgmt_async
#define hinic3_msg_to_mgmt_no_ack    sdk_msg_to_mgmt_no_ack
#define hinic3_msg_to_mgmt_sync    sdk_msg_to_mgmt_sync
#define hinic3_ppf_tmr_start    sdk_ppf_tmr_start
#define hinic3_ppf_tmr_stop    sdk_ppf_tmr_stop
#define hinic3_register_mgmt_msg_cb    sdk_register_mgmt_msg_cb
#define hinic3_register_pf_mbox_cb    sdk_register_pf_mbox_cb
#define hinic3_register_ppf_mbox_cb    sdk_register_ppf_mbox_cb
#define hinic3_register_service_adapter    sdk_register_service_adapter
#define hinic3_register_vf_mbox_cb    sdk_register_vf_mbox_cb
#define hinic3_set_root_ctxt    sdk_set_root_ctxt
#define hinic3_sm_ctr_rd64    sdk_sm_ctr_rd64
#define hinic3_unregister_mgmt_msg_cb    sdk_unregister_mgmt_msg_cb
#define hinic3_unregister_pf_mbox_cb    sdk_unregister_pf_mbox_cb
#define hinic3_unregister_ppf_mbox_cb    sdk_unregister_ppf_mbox_cb
#define hinic3_unregister_service_adapter    sdk_unregister_service_adapter
#define hinic3_unregister_vf_mbox_cb    sdk_unregister_vf_mbox_cb
#define hinic3_mbox_ppf_to_host   sdk_mbox_ppf_to_host
#define hinic3_set_ceq_irq_disable   sdk_set_ceq_irq_disable
#define hinic3_force_complete_all   sdk_force_complete_all
#define hinic3_get_ceq_page_phy_addr sdk_get_ceq_page_phy_addr
#define hinic3_get_ceq_info    sdk_get_ceq_info

#endif
#endif
